package leetcode;

import util.TreeNode;

/**
 * @Project : AlgorithmLearning
 * @Package : Leetcode
 * @File : Q0108.java
 * @Author : WangRuoyu
 * @Date 2023/11/16 15:51
 */


public class Q0108 {
    private TreeNode dfs(int[] nums, int l, int r) {
        if (l > r) return null;
        if (l == r) return new TreeNode(nums[l]);
        int mid = l + r >> 1;
        TreeNode node = new TreeNode(nums[mid]);
        node.left = dfs(nums, l, mid - 1);
        node.right = dfs(nums, mid + 1, r);
        return node;
    }

    public TreeNode sortedArrayToBST(int[] nums) {
        return dfs(nums, 0, nums.length - 1);
    }

    public static void main(String[] args) {
        Q0108 sl = new Q0108();
    }
}